// Copyright DustedPixels.com 2008. All rights reserved.

package kroff;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class Mem64Kb implements Runnable {
  private final byte[] array = new byte[0x10000];
  
  private final Bus addr;
  private final Bus data;
  private final Pin write;
  
  public Mem64Kb(Bus addr, Bus data, Pin write) {
    this.addr = addr;
    this.data = data;
    this.write = write;
  }
  
  public void run() {
    if (write.get()) {
      data.set(array[addr.get() & 0xFFFF]);
    } else {
      array[addr.get() & 0xFFFF] = (byte) data.get();
    }
  }
}
